

/*------------------------------------------------------------------------------
	1. Housekeeping
------------------------------------------------------------------------------*/
	*Run housekeeping code
		qui do ".../replication_package/housekeeping.do"

	*Write log
		log using "$log_loc/figure_a4.log", text replace

/*------------------------------------------------------------------------------
	3. Clean Main Datasets
------------------------------------------------------------------------------*/

		*Import Data
		use "$data/childrens2021.dta", clear

			/*Restrict Sample*/
				*Keep 1095 filings
					rename state_insurance state
					fmerge m:1 state using "$data/statelist.dta"
						assert _merge != 2 //Confirm that all 51 states are in dataset
						drop if _merge != 3
						drop _merge

				*Keep if age_num is within the range
					keep if age_num >= 0 & age_num <= 16

				*Keep if kid died after end of year or is currently alive
					keep if 2021*10000+1231<death_date|death_date==0

				*Keep if months covered is possible
					keep if num_cov_ins > 0 & num_cov_ins <= 12

			/*Generate variables for figures*/	
				*Generate outcame variable on claiming
					gen onreturn = file_inc != .

				*Generate a count variable
					gen ct = 1

				*Collapse to the by-age_num level
					collapse (sum) ct onreturn, by(age_num)

				*Merge in Census Data
					gen year = 2021

				*Adjust for claiming limits
					replace onreturn = onreturn * 1.0017029

				*Generate outcome (i.e., percent of children claimed)
					gen perc_return = onreturn/ct
			
				*Adjust outcome to be out of 100
					replace perc_return = perc_return*100

/*------------------------------------------------------------------------------
	4. Create Figure 1
------------------------------------------------------------------------------*/

			/*Create Figures*/	
				*Create Graph
				twoway 	(connected perc_return age_num, msymbol(o) mlcolor(gs1) mfcolor(white) clcolor(gs1) lpattern(dash)) , ///
					ylabel(, format(%5.1f) labsize(small)) ///
					xtitle("Age", height(4)) ///
					xlabel(0(1)16, labsize(small)) ///	
					ytitle("Share Claimed (%)", size(medsmall)) ///
					legend(off) ///
					graphregion(fcolor(white) color(white) lcolor(white))

				*Export Graph
					graph export "${output}/2021 by age.png", replace as(png)
